<%@ include file="/WEB-INF/jsp/include.jsp"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<c:choose>
    <c:when test="${usersTable.id > 0}">
        <c:set var="page_title"  value="edit user's table"/>
    </c:when>
    <c:otherwise>
        <c:set var="page_title"  value="Add new user's table"/>
    </c:otherwise>
</c:choose>

<html>
<head>
    <title><c:out value="${page_title}"/></title>
</head>
<body>
<c:import url="../pagemenus/mainUserMenu.jsp"/>
<br/>
<h3><c:out value="${page_title}"/></h3>

<form action="<c:url value="/usertable-save.html"/>" method="post">
<form:hidden path="usersTable.id"/>
<table>
    <tr>
        <td>name</td>
        <td>
            <spring:bind path="usersTable.name">
                <form:input path="usersTable.name" />
                <c:out value="${status.errorMessage}"/>
            </spring:bind>
        </td>
    </tr>
    <tr>
        <td>permanent</td>
        <td>
            <form:checkbox path="usersTable.permanent"/>
        </td>
    </tr>
    <tr>
        <td>from</td>
        <td>
            <spring:bind path="usersTable.from">
                <form:input path="usersTable.from" />
                <c:out value="${status.errorMessage}"/>
            </spring:bind>
        </td>
    </tr>
    <tr>
        <td>to</td>
        <td>
            <spring:bind path="usersTable.to">
                <form:input path="usersTable.to" />
                <c:out value="${status.errorMessage}"/>
            </spring:bind>
        </td>
    </tr>
    <tr>
        <td>periodLength</td>
        <td>
            <spring:bind path="usersTable.periodLength">
                <form:input path="usersTable.periodLength" />
                <c:out value="${status.errorMessage}"/>
            </spring:bind>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Save">
        </td>
    </tr>
</table>
</form>
<c:if test="${usersTable.id > 0}">
    <table border="1">
        <tr>
            <th>day menus</th>
        </tr>

        <c:forEach var="dayMenu" items="${usersTable.dayMenusByDay}" varStatus="dmSt">
        <tr>
            <td>
            <c:choose>
                <c:when test="${dayMenu == null}">
                    <form action="<c:url value="/daymenus-add.html"><c:param name="usersTableId" value="${usersTable.id}"/></c:url>" method="post">
                        <input type="hidden" value="${dmSt.index}" name="dayNumber">
                        <input type="submit" value="add for day(${dmSt.index + 1})">
                    </form>
                </c:when>
                <c:otherwise>
                    day menu for day number ${dayMenu.dayNumber + 1}
                    <a href="<c:url value="/daymenus-get.html"><c:param name="usersTableId" value="${usersTable.id}"/><c:param name="id" value="${dayMenu.id}"/></c:url>">View</a>
                    &nbsp;&nbsp;&nbsp;
                    <a href="<c:url value="/daymenus-remove.html"><c:param name="usersTableId" value="${usersTable.id}"/><c:param name="id" value="${dayMenu.id}"/></c:url>">Remove</a>
                </c:otherwise>
            </c:choose>
            </td>
        </tr>
        </c:forEach>
    </table>
</c:if>
</body>
</html>
